package com.api.main.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Demo {

    public static void main(String[] args) throws IOException {
        //exportVoteExcel("测试导出excel表", "sheet1");

        String fileName = "课后评价调查-23090667507151.xlsx";

        String regex = "-(\\d+)";

        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(fileName);
        if (matcher.find()) {
            String number = matcher.group(1);
            System.out.println("提取的编号是：" + number);
        } else {
            System.out.println("未找到匹配的编号");
        }

    }

    public static <T> void exportVoteExcel(String fileName, String sheetName) throws IOException {
        String[] header_1 = new String[]{"111", "提交人用户名", "提交人用户名"};
        String[] header_2 = new String[]{"111", "提交人姓名", "提交人姓名"};
        String[] header_3 = new String[]{"111", "创建时间", "创建时间"};
        String[] header_4 = new String[]{"222", "更新时间", "更新时间"};
        String[] header_5 = new String[]{"222", "学习经历", "时间"};
        String[] header_6 = new String[]{"222", "学习经历", "学校"};
        String[] header_7 = new String[]{"333", "学习经历", "专业"};
        String[] header_8 = new String[]{"333", "学习经历", "学位"};
        String[] header_9 = new String[]{"444", "工作单位", "工作单位"};
        String[] header_10 = new String[]{"444", "国籍", "国籍"};
        String[] header_11 = new String[]{"444", "获奖经历", "时间"};
        String[] header_12 = new String[]{"555", "获奖经历", "何种奖励"};

        File result = File.createTempFile(fileName, ".xlsx", new File("/Users/zhangwj/Downloads"));
        try (FileOutputStream outputStream = new FileOutputStream(result)) {
            ExcelUtil.export(outputStream, sheetName, headers(header_1, header_2, header_3, header_4, header_5,
                    header_6, header_7, header_8, header_9, header_10, header_11, header_12), data());
        } catch (IOException e) {
            System.out.println("导出异常");
        }
    }

    private static List<List<String>> headers(String[]... headers) {
        if (null == headers || headers.length == 0) {
            return null;
        }
        List<List<String>> headerList = new ArrayList<>(headers.length);
        for (String[] header : headers) {
            headerList.add(Arrays.asList(header));
        }
        return headerList;
    }

    private static List<List<String>> data() {
        List<List<String>> data = new ArrayList<>();
        data.add(Arrays.asList("fengqingyang", "风清扬", "2022-01-25 11:08", "2022-01-25 11:08", "2013.9 ~ 2017.7", "华山派", "剑宗", "剑宗高手", "隐居思过崖", "中国", "2015.12", "华山剑法高手"));
        data.add(Arrays.asList("fengqingyang", "风清扬", "2022-01-25 11:08", "2022-01-25 11:08", "2017.9 ~ 2020.7", "独孤求败", "独孤剑法", "剑术通神", "隐居思过崖", "中国", "2019.12", "剑法高手"));
        data.add(Arrays.asList("linghuchong", "令狐冲", "2022-01-25 12:08", "2022-01-25 12:08", "2020.9 ~ 2024.7", "华山派", "气宗", "气宗庸手", "漂泊江湖", "中国", "2022.12", "华山剑法庸手"));
        data.add(Arrays.asList("linghuchong", "令狐冲", "2022-01-25 12:08", "2022-01-25 12:08", "2024.9 ~ 2027.7", "风清扬", "独孤剑法", "剑法高手", "漂泊江湖", "中国", "2025.12", "剑法高手"));
        data.add(Arrays.asList("linghuchong", "令狐冲", "2022-01-25 12:08", "2022-01-25 12:08", "2027.9 ~ 2030.7", "少林寺", "易筋经", "内功高手", "漂泊江湖", "中国", "2029.12", "内功高手"));
        return data;
    }
}